<?php
namespace app\shop\home;

use app\shop\model\Banner;
use app\shop\model\Artwork;
use app\shop\model\Artist;
use app\shop\model\ArtworkGroup;

use app\admin\model\Attachment;
/**
 * 艺术家
 */
class Artists extends Common
{
    public function group()
    {
    	//艺术家
        $artist = Artist::with('getimgpath')->order('group')->select();
        $banners =Banner::with('getimgpath')->where('status', 1)->where('group',2)->order('sort')->select();

        foreach ($artist as $k => &$v) {
        	$artists[$v['group']][] = $v;
        }
     
        $this->assign('artist', $artists);
        $this->assign('banners', $banners);


        if(isMobile()){
            return $this->fetch('Mobile/artists/group');
        }else{
            return $this->fetch();
        }
    }

    public function detail()
    {
    	$info = Artist::with('getimgpath')->where('id',request()->param('id'))->find();

    	$artwork = Artwork::with('getartist')->where('artist_id', $info['id'])->select();
        foreach ($artwork as $k => &$v) {
            $artistIn[] = $v['artist_id'];
            $in = explode(',', $v['photos']);
            $ins = [];
            for($i = 0; $i <count($in); $i++){
                $imgs = Attachment::where('id',$in[$i])->value('path');
               $ins[] = $imgs;
            }
             $artwork[$k]['img'] = $ins;
        }
    	//var_dump($info);die;
    	$this->assign('info', $info);
    	$this->assign('artworks', $artwork);
        if(isMobile()){
            return $this->fetch('Mobile/artists/detail');
        }else{
            return $this->fetch();
        }
    }
}